<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>
    <div id="time"></div>
    <img src="./images/off.png" alt="" id="light">

    <!-- 内部脚本 -->
    <script>
        // alert("hello world1");
        let img = document.querySelector("#light")
        let div = document.querySelector("#time")
        div.innerHTML = new Date().toLocaleString()
        let count = 2;
        setInterval(function () {
            div.innerHTML = new Date().toLocaleString()
            // count ++;
            if (count % 2 == 0) {
                img.src = "./images/on.png"
                count = 1;
                return
            }
            img.src = "./images/off.png"
            count ++;
        }, 1000) 
    </script>
    <!-- 外部引入 在script 内部不能写其他内容 -->
    <!-- <script src="./js/window.js"></script> -->
    <script>
        // // chengfa();
        // let str = "hello"
        // let str2 = new String("world")
        // // length 是字符串的属性
        // console.log(str.length);
        // console.log(str.indexOf('e'));
        // console.log(str.charAt(2));

        // // 日期对象
        // let date = new Date()
        // console.log(date);
        // // 格式化日期 yyyy/MM/dd hh:mm:ss  yyyy-MM-dd HH:mm:ss
        // console.log(date.toLocaleString());
        // console.log("年", date.getFullYear());
        // console.log("月", date.getMonth() + 1);
        // console.log("日", date.getDate());
        // console.log("周", date.getDay());
        // console.log("小时", date.getHours());
        // console.log("分钟", date.getMinutes());
        // console.log("秒", date.getSeconds());

        // let format = (date) => {
        //     //
        //     let year = date.getFullYear()
        //     let month = date.getMonth() + 1
        //     let day = date.getDate()
        //     let hour = date.getHours()
        //     let minute = date.getMinutes()
        //     let second = date.getSeconds()
        //     return year + "-" + (month > 10 ? month : "0" + month) + "-" + day + " "
        //     + hour + ":" + minute + ":" + (second > 10 ? second : "0" + second)
        // }

        // console.log(format(new Date()));


    </script>
</body>

</html>